#作业编写日志记录装饰器
#比如执行了func1函数，那就日志记录“执行了func1函数，花费多久时间” ，日志的格式要包含时间
#日志要输出到文件（sc.log）和屏幕


import logging
import time

logger = logging.getLogger()

fh = logging.FileHandler("sc.log1")

ch = logging.StreamHandler()

formatter = logging.Formatter("%(asctime)s-%(levelname)s:%(message)s")

fh.setFormatter(formatter)
ch.setFormatter(formatter)

logger.addHandler(fh)
logger.addHandler(ch)

logger.setLevel(logging.DEBUG)

def log_record(func):
    def inner():
        start = time.time()
        func()
        end = time.time()
        logger.warning(f"执行了{func.__name__}函数，花费{end-start:.2f}s")
    return inner

@log_record
def func():
    time.sleep(2)

func()












